package com.example.vae.Adapter;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.vae.Pojo.HomeInformation;
import com.example.vae.R;

import java.util.List;

//这个是初始化Find 页面的 Adapter
public class HomeRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    Context context;
    private LayoutInflater layoutInflater;
//    private List<Integer> imageviews;
//    private List<String> strings;

    private List<HomeInformation> list;
    public HomeRecyclerViewAdapter(Context context){
        this.context = context;
    }
    public HomeRecyclerViewAdapter(Context context, List<HomeInformation> list){
        this.context=context;
       this.list=list;
        layoutInflater=LayoutInflater.from(context);
    }

    //    初始化item布局
    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

       View view=layoutInflater.inflate(R.layout.home_item,parent,false);
        DisplayMetrics dm=context.getResources().getDisplayMetrics();
        int height=dm.heightPixels;
        view.getLayoutParams().height=height/5;
        MyViewHolder myViewHolder=new MyViewHolder(view);
        return myViewHolder;
    }

    //    处理每一个item 的地方,绑定数据
    @Override
    public void onBindViewHolder( RecyclerView.ViewHolder holder, int position) {

        MyViewHolder myViewHolder=(MyViewHolder)holder;

       myViewHolder.content.setText(list.get(position).getContext());
       myViewHolder.title.setText(list.get(position).getTitle());
       myViewHolder.item_type.setText(list.get(position).getItem_type());
       myViewHolder.good_number.setText(String.valueOf(list.get(position).getGood_number()));
       myViewHolder.mes_number.setText(String.valueOf(list.get(position).getMes_number()));
       myViewHolder.item_img.setImageResource(list.get(position).getItem_img());
       myViewHolder.time.setText(list.get(position).getDate());


    }

    //    显示数量，因为我的布局文件就是三个，所以我返回san
    @Override
    public int getItemCount() {
        return list.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder{

        private ImageView item_img,img_mes,img_good;
        private TextView title,content,time,mes_number,good_number,item_type;


        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
           title=itemView.findViewById(R.id.title);
            content=itemView.findViewById(R.id.content);
            time=itemView.findViewById(R.id.time);
            mes_number=itemView.findViewById(R.id.mes_number);
            good_number=itemView.findViewById(R.id.good_number);
            item_img=itemView.findViewById(R.id.item_img);
            img_mes=itemView.findViewById(R.id.img_mes);
            img_good=itemView.findViewById(R.id.img_good);
            item_type=itemView.findViewById(R.id.item_type);
        }
    }

}